--[[
组队自动匹配逻辑
接口列表：
signIn			个人报名
signInTeam      队伍报名
--]]

local MapExcel = require("excel.Map")
local CopyConfig = MapExcel.copy
local Msg = require("core.Msg")
local Timer = require("core.Timer")
local CopyDefine = require("copy.Define")
local Copy = require("copy.CopyW")
local TeamLogic = require("team.TeamLogic")
local Broadcast = require("broadcast.Broadcast")
local Lang = require("common.Lang")
local CopyCommon = require("copy.CopyCommon")
local Human = require("core.Human")
local HtmlUtil = require("common.HtmlUtil")
local ActDefine = require("activity.Define")
local DailyActFW = require("activity.DailyActFW")


SIGN_STATUS_MATCH     = 0
SIGN_STATUS_READY     = 1
SIGN_TEAM_COUNT_MAX = 3
NOT_READY_KICK_TIME = 10000				  -- 10秒不准备自动踢出匹配队列

EXIT_SIGN_TYPE_NORMAL = 0  --主动退出
EXIT_SIGN_TYPE_CONDITON = 1 --条件不足退出
EXIT_SIGN_TYPE_TEAM    = 2  --被队长带退出
EXIT_SIGN_TYPE_NOREADY = 3  --没有准备被删出
EXIT_SIGN_TYPE_FINISH = 4 --匹配进副本成功后关掉界面
EXIT_SIGN_TYPE_TEAM_EXIT = 5 --队员退出队伍
EXIT_SIGN_TYPE_COPY_OTHER = 6

signHuman2CopyID = signHuman2CopyID or {}			-- 报名uuid->copyID
signTeamData = signTeamData or {}					-- 报名数据


local function findSignData(uuid, copyID)
    signTeamData[copyID] = signTeamData[copyID] or {}
    local signData = signTeamData[copyID]
    for i = 1, #signData do
        for j = 1, #signData[i] do
            if signData[i][j].uuid == uuid then
                return signData[i], i
            end
        end
    end  
end 
local function changeStatus(match, status)
    for i = 1, #match do
        match[i].status = status
    end
end

function sign(human, copyID)
    local copyConfig = CopyConfig[copyID]
    if not copyConfig or copyConfig.type ~= CopyDefine.COPY_TYPE_TEAM then
        return
    end
    if copyID == CopyDefine.COPY_GMTX_COPY_ID then
        if not DailyActFW.onCheckActIsRunning(ActDefine.ACT_TYPE_GMTX_ACT) then
            Broadcast.sendBroadcast(human, Lang.DOWN, Lang.GMTX_NOT_START)  --活动暂未开启
            return
        end
    end
    if signHuman2CopyID[human._id] then
        if signHuman2CopyID[human._id] == copyID then
            local match = findSignData(human._id , copyID)       
            if match then              
                sendSignList(copyID, match, human)
                return
            end
            signHuman2CopyID[human._id] = nil           
        else
            --删掉之前的匹配
            local copyID = signHuman2CopyID[human._id]
            local ids = remove(human._id, signHuman2CopyID[human._id])
            if ids and #ids > 1 then
                local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
                msg.copyID = copyID
                msg.exitType = EXIT_SIGN_TYPE_TEAM
                for i = 2, #ids do
                    Msg.send(msg, Human.onlineUuid[ids[i]].fd)
                end
            end
        end
    end

    local team = TeamLogic.getTeamByUuid(human._id)  
    if team then
        signTeam(human, copyID, team)      
    else
        signIn(human, copyID)
    end   
end
-- 单人报名
function signIn(human, copyID)  
    local err = CopyCommon.checkEnterCondition(human, copyID) 
    if err then
        Broadcast.sendBroadcast(human, Lang.MOUSE, err)
        return
    end
    signTeamData[copyID] = signTeamData[copyID] or {}
    signHuman2CopyID[human._id] = copyID
    local data = signTeamData[copyID]
    local match
    local avg = 10000
    for i = 1, #data do  --先找只差一个人的
        if SIGN_TEAM_COUNT_MAX - #data[i] == 1 then
            local sum = human.db.lv
            for j = 1, #data[i] do
                sum = data[i][j].lv + sum
            end
            local avgVal = math.abs(sum/SIGN_TEAM_COUNT_MAX - human.db.lv)
            if avgVal < avg then
                match = data[i]
                avg = avgVal
            end
        end
    end
    if match then
        match[#match+1] = {uuid = human._id, status = SIGN_STATUS_MATCH, lv = human.db.lv, uid = match[1].uid}
        sendSignList(copyID, match)
        return
    end
    for i = 1, #data do  --匹配其它
        match = data[i]
        if #match < SIGN_TEAM_COUNT_MAX then
            match[#match+1] = {uuid = human._id, status = SIGN_STATUS_MATCH, lv = human.db.lv, uid = match[1].uid}
            sendSignList(copyID, match)
            return
        end
    end
    data[#data + 1] = {}  --都满了，新建一个
    data[#data][1] = {uuid = human._id, status = SIGN_STATUS_MATCH, lv = human.db.lv, uid = os.time()}
    sendSignList(copyID, data[#data])  
end


--组队报名
function signTeam(human, copyID, team)
    local leaderUuid = TeamLogic.getLeaderUuid(team)
    if leaderUuid ~= human._id then -- 只有队长才能匹配       
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_MATCH_NOTLEADER)          
        return
    end
    local uuids = {}
    local sumLv = 0
    for i = 1, TeamLogic.TEAM_MAX_MEMBER_COUNT do
        if team[i] ~= nil and Human.onlineUuid[team[i].uuid] ~= nil  then
            if Human.onlineUuid[team[i].uuid].fd then
                local err = CopyCommon.checkEnterCondition(Human.onlineUuid[team[i].uuid], copyID) 
                if err then
                    if i > 1 then
                        err = "您的队友"..err
                    end
                    Broadcast.sendBroadcast(human, Lang.MOUSE, err)  
                    return
                end
                uuids[#uuids + 1] = {uuid = team[i].uuid, status = SIGN_STATUS_MATCH, lv = Human.onlineUuid[team[i].uuid].db.lv}
                sumLv = sumLv + uuids[#uuids].lv
            end
        end
    end
    if #uuids  == 1 then --只有一个人的队伍
        TeamLogic.exit(human._id)
        signIn(human, copyID)
        return
    end
    for j = 1, #uuids do
        signHuman2CopyID[uuids[j].uuid] = copyID
    end
    signTeamData[copyID] = signTeamData[copyID] or {}
    local data = signTeamData[copyID]
    if #uuids == SIGN_TEAM_COUNT_MAX then
        data[#data + 1] = uuids
        for j = 1, #uuids do
            uuids[j].uid = os.time()
        end
        sendSignList(copyID, data[#data])
        return 
    end    
    sumLv = sumLv / #uuids
    local matchIndex
    local match
    local diffLv = 10000
    for i = 1, #data do  -- 2找1
        if #data[i] == 1 then
            if math.abs(sumLv - data[i][1].lv) < diffLv then
                matchIndex = i
                match = data[i]
                diffLv = math.abs(sumLv - data[i][1].lv)
            end
        end
    end
    if match then
        for j = 1, #uuids do
            uuids[j].uid = match[1].uid
        end
        for j = 1, #match do
            uuids[#uuids + 1] = match[j]
        end           
        data[matchIndex] = uuids        
        sendSignList(copyID, uuids)
        return   
    end
    data[#data + 1] = {} 
    local match = data[#data]
    for j = 1, #uuids do
        match[#match + 1] = uuids[j]
        uuids[j].uid = os.time()
    end
    sendSignList(copyID, match) 
end

function getFDs(match)
    local ids = {}
    for i = #match, 1, -1 do
        local human = Human.onlineUuid[match[i].uuid]
        if human and human.fd then
            ids[#ids + 1] = human.fd
        end
    end
    ids[0] = #ids
    return ids    
end
--发送匹配信息
function sendSignList(copyID, match, human)      
    local msg = Msg.gc.GC_COPY_TEAM_SIGN_LIST
    local copyConfig = CopyConfig[copyID]
    msg.copyID = copyID
    msg.difficult = copyConfig.difficult
    msg.name = copyConfig.name
    local ids = {}

    for i = 1, #match do
        local human = Human.onlineUuid[match[i].uuid]
        msg.members[i].uuid = match[i].uuid
        msg.members[i].name = human.name
        msg.members[i].sex = human.db.sex
        Human.makeViewInfo(msg.members[i].viewInfo, human.db.sex, Human.getRealBodyInfo(human.db))
        msg.members[i].status = match[i].status
        msg.members[i].lv = match[i].lv
        if human.fd then
            ids[#ids + 1] = human.fd
        end
    end
    msg.members[0] = #match
    ids[0] = #ids
    if human then
        Msg.send(msg, human.fd)
    else
        Msg.sendMulti(msg, ids)
    end
end

--准备
function signReady(human, copyID)
    local copyConfig = CopyConfig[copyID]
    if not copyConfig or copyConfig.type ~= CopyDefine.COPY_TYPE_TEAM then
        return
    end
    if signHuman2CopyID[human._id] ~= copyID then
        return
    end
    local match
    local index

    match,index = findSignData(human._id, copyID)
    if not match then
        return
    end
    
    if copyID == CopyDefine.COPY_GMTX_COPY_ID then
        if not DailyActFW.onCheckActIsRunning(ActDefine.ACT_TYPE_GMTX_ACT) then
            Broadcast.sendBroadcast(human, Lang.DOWN, Lang.GMTX_NOT_START)  --活动暂未开启
            removeAll(copyID, match, index)
            return
        end
    end
    
    if match[1].uuid == human._id then --队长。
        return startCopy(human, copyID,match, index)
    end
    local pos 
    for i = 1, #match do
        if match[i].uuid == human._id and match[i].status == SIGN_STATUS_MATCH then                  
            match[i].status = SIGN_STATUS_READY         
            pos = i    
            break
        end
    end
    sendSignList(copyID, match)
end

--remove
function remove(uuid, copyID, match, index)
    if signHuman2CopyID[uuid] ~= copyID then
        return
    end 
    local signData = signTeamData[copyID]
    if not match or not index then
        match, index = findSignData(uuid, copyID)
    end   
    if not match then
        signHuman2CopyID[uuid] = nil
        return
    end
    local removeUuids = {}
    local team = TeamLogic.getTeamByUuid(uuid)  
    if match[1].uuid == uuid and team and team[1].uuid == uuid then       --队长退出匹配，队员也要退出
        for i = 1, TeamLogic.TEAM_MAX_MEMBER_COUNT do
            if team[i] ~= nil and Human.onlineUuid[team[i].uuid] ~= nil  then
                    for j = #match, 1, -1 do
                        if match[j].uuid == team[i].uuid then
                            match[j] = match[#match]
                            match[#match] = nil
                            removeUuids[#removeUuids + 1] = team[i].uuid
                            signHuman2CopyID[team[i].uuid] = nil
                            break
                        end
                    end
            end
        end
    else   -- 删除个人
        for j = #match, 1, -1 do
            if match[j].uuid == uuid then
                match[j] = match[#match]
                match[#match] = nil
                removeUuids[1] = uuid
                signHuman2CopyID[uuid] = nil
                break
            end
        end  
    end   

    if #removeUuids > 0 then
        if #match > 0 then
            match[1].startTime = nil
            match[1].applyRoom = nil
            changeStatus(match, SIGN_STATUS_MATCH)
            sendSignList(copyID, match)
        else
            signData[index] = signData[#signData]
            signData[#signData] = nil
        end
        return removeUuids
    end
end

--退出匹配
function signExit(human, copyID)
    local copyConfig = CopyConfig[copyID]
    if not copyConfig or copyConfig.type ~= CopyDefine.COPY_TYPE_TEAM then
        return
    end   
    if signHuman2CopyID[human._id] ~= copyID then
        return
    end   
    local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
    msg.copyID = copyID
    msg.exitType = EXIT_SIGN_TYPE_NORMAL
    local ids =  remove(human._id, copyID)
    if not ids then
        Msg.send(msg, human.fd)
        return
    end
    for i = 1, #ids do
        if ids[i] == human._id then
            msg.exitType = EXIT_SIGN_TYPE_NORMAL
        else
            msg.exitType = EXIT_SIGN_TYPE_TEAM
        end
        Msg.send(msg, Human.onlineUuid[ids[i]].fd)
    end
end

function startCopy(human, copyID, match, index)
    if match[1].uuid ~= human._id then --非队长，不能开启
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_ENTER_ERR_NO_TEAMLEADER)
        return
    end
    if match[1].status ==  SIGN_STATUS_READY then
        return
    end
    for i = 1, #match do
        local err = CopyCommon.checkEnterCondition(Human.onlineUuid[match[i].uuid], copyID) 
        if err then
            if i ~= 1 then
                err = "您的队友"..err
            end
            remove(match[i].uuid, copyID, match, index)
            Broadcast.sendBroadcast(human, Lang.MOUSE, err)
            return
        end
    end
    --队长
    local msg = Msg.gc.GC_COPY_TEAM_LEADER_READY
    msg.copyID = copyID
    msg.second = NOT_READY_KICK_TIME/1000
    msg.leaderUuid = human._id
    local fds = getFDs(match)
    if fds[0] > 0 then
        Msg.sendMulti(msg, fds)
    end   
    match[1].startTime = Timer.now + NOT_READY_KICK_TIME
    match[1].status =  SIGN_STATUS_READY
    match[1].applyRoom = nil
end


--正式开始 一个匹配
function realStartCopy(copyID, match, index)
    local ids = {}
    local len = 0
    for i = 1, #match do
        len = len + 1
        ids[len] = match[i].uuid
    end
    local exit
    for i = 1, len do
        local err = CopyCommon.checkEnterCondition(Human.onlineUuid[ids[i]], copyID) 
        if err then
            local removeUuids = remove(ids[i], copyID, match, index)
            if removeUuids then
                local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
                msg.copyID = copyID
                msg.exitType = EXIT_SIGN_TYPE_CONDITON
                for j = 1, #removeUuids do
                    Msg.send(msg, Human.onlineUuid[removeUuids[j]].fd)
                end
                exit = true
            end
        end
    end
    if exit then
        return
    end   
    len = 0
    for i = 1, #match do
        if match[i].status ~= SIGN_STATUS_READY then
            len = len + 1
            ids[len] = match[i].uuid
        end
    end
    for i = 1, len do
        local removeUuids = remove(ids[i], copyID, match, index)
        if removeUuids then
            local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
            msg.copyID = copyID
            msg.exitType = EXIT_SIGN_TYPE_NOREADY
            for j = 1, #removeUuids do
                Msg.send(msg, Human.onlineUuid[removeUuids[j]].fd)                  
            end              
        end       
    end
    if len > 0 then
        Broadcast.sendBroadcastFDs(getFDs(match), Lang.DOWN, Lang.COPY_SIGN_NOT_READY)  
        return
    end
    match[1].applyRoom = copyID
    Copy.applyCopyRoom(Human.onlineUuid[match[1].uuid], copyID, os.time())
end

function finishApplyCopyRoom(uuid, realCopyID, roomID)
    if roomID == 0 then
        return
    end
    local copyID = signHuman2CopyID[uuid]
    if copyID == nil then
        return
    end
    local match, index = findSignData(uuid, copyID)
    if not match then
        return
    end
    if match[1].uuid ~= uuid or match[1].applyRoom ~= realCopyID then
        return 1 --已经变了，去掉
    end
    local fds = getFDs(match)
    if roomID == 0 then        
        if fds[0] > 0 then
            Broadcast.sendBroadcastFDs(fds, Lang.TEAM+Lang.DOWN, Lang.COPY_ENTER_ERR_COPY_FULL)
        end
        match[1].startTime = nil
        match[1].applyRoom = nil
        changeStatus(match, SIGN_STATUS_MATCH)

        sendSignList(copyID, match)
        return 1
    end
    local msg = Msg.wl.WL_CROSS_ROOM_APPLY_RESULT
    msg.copyid = realCopyID
    msg.roomid = roomID
    for i = 1, #match do
        Msg.send2logic(msg, match[i].uuid)
    end

    msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
    msg.copyID = copyID
    msg.exitType = EXIT_SIGN_TYPE_FINISH
    if fds[0] > 0 then
        Msg.sendMulti(msg, fds)
    end
    for i = 1, #match do
        signHuman2CopyID[match[i].uuid] = nil
    end
    signTeamData[copyID][index] = signTeamData[copyID][#signTeamData[copyID]]
    signTeamData[copyID][#signTeamData[copyID]] = nil

    for i = 1, #match do --重新组队
        TeamLogic.exit(match[i].uuid)
    end
    --创建新的队伍
    local leader = Human.onlineUuid[match[1].uuid]
    TeamLogic.create(leader)
    local team = TeamLogic.getTeamByUuid(leader._id)   
    for i = 2, #match do 
        TeamLogic.addMember(team, Human.onlineUuid[match[i].uuid])
    end
    TeamLogic.sendLists(team)
    return 2
end


--招募
function ad(human, copyID)
    local copyConfig = CopyConfig[copyID]
    if not copyConfig or copyConfig.type ~= CopyDefine.COPY_TYPE_TEAM then
        return
    end
    if signHuman2CopyID[human._id] == nil then
        return
    end
    local sign = findSignData(human._id, copyID)
    if not sign then
        signHuman2CopyID[human._id] = nil
        return
    end
    local name = copyConfig.name
    local diff = CopyCommon.getCopyDifficult(copyConfig.difficult)
    if diff then
        name = name.."-"..diff.."难度"
    end
    Broadcast.sendBroadcast2World(Lang.WORLD, string.format(Lang.COPY_TEAM_INVITE_AD, HtmlUtil.fontName(human.name, human._id), name, human._id, copyID, sign[1].uid))
end

--加入
function signJoin(human, uuid, copyID, uid)
    local copyConfig = CopyConfig[copyID]
    if not copyConfig or copyConfig.type ~= CopyDefine.COPY_TYPE_TEAM then
        return
    end  
    if human._id == uuid then
        return
    end
    if signHuman2CopyID[human._id] then
        if findSignData(human._id, signHuman2CopyID[human._id]) then
            Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_MATCH_HAD)
            return
        end
        signHuman2CopyID[human._id] = nil
    end
    if signHuman2CopyID[uuid] == nil or signHuman2CopyID[uuid] ~= copyID then
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_START)      
        return
    end
    local sign, index = findSignData(uuid, copyID)
    if not sign or sign[1].applyRoom then
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_START)      
        return
    end
    if sign[1].uid ~= uid then
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_END)   
        return
    end
    if #sign >= SIGN_TEAM_COUNT_MAX then
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_MATCH_FULL)
        return
    end
    local err = CopyCommon.checkEnterCondition(human, copyID)  --条件不满足
    if err then
        Broadcast.sendBroadcast(human, Lang.MOUSE, err)
        return      
    end
    local team = TeamLogic.getTeamByUuid(human._id)  
    if team and TeamLogic.getLeaderUuid(team) ~= human._id then --只有队长才能参加匹配
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_MATCH_NOTLEADER)
        return
    end
    if not team then --个人
        sign[#sign + 1] = {uuid = human._id, status = SIGN_STATUS_MATCH, lv = human.db.lv, uid = sign[1].uid}
        signHuman2CopyID[human._id] = copyID
        sign[1].startTime = nil
        sign[1].applyRoom = nil
        changeStatus(sign, SIGN_STATUS_MATCH)
        sendSignList(copyID, sign)
        return
    end
    --队伍
    local uuids = {}
    for i = 1, TeamLogic.TEAM_MAX_MEMBER_COUNT do
        if team[i] ~= nil and Human.onlineUuid[team[i].uuid] ~= nil  then
            if Human.onlineUuid[team[i].uuid].fd then
                local err = CopyCommon.checkEnterCondition(Human.onlineUuid[team[i].uuid], copyID) 
                if err then
                    Broadcast.sendBroadcast(human, Lang.MOUSE, "您的队友"..err)  
                    return
                end
                uuids[#uuids + 1] = {uuid = team[i].uuid, status = SIGN_STATUS_MATCH, lv = Human.onlineUuid[team[i].uuid].db.lv}          
            end
        end
    end
    if SIGN_TEAM_COUNT_MAX - #sign < #uuids then
        Broadcast.sendBroadcast(human, Lang.MOUSE, Lang.COPY_TEAM_INVITE_CANNOT_MATCH_TOOMANY)  
        return
    end
    for j = 1, #uuids do
        signHuman2CopyID[uuids[j].uuid] = copyID
        uuids[j].uid = sign[1].uid
    end
    if #sign > 1 then
        for j = 1, #uuids do
            sign[#sign + 1] = uuids[j]
        end
    else
        for j = 1, #sign do
            uuids[#uuids + 1] = sign[j]
        end           
        signTeamData[copyID][index] = uuids
        sign = uuids
    end
    sendSignList(copyID, sign)
end
-- 1s定时器
timer_cnt = timer_cnt or 0
function onTimer1Second()
    local cnt = 0
    timer_cnt = timer_cnt + 1
    for copyID, signData in pairs(signTeamData) do
        for i = #signData, 1, -1 do
            local members = signData[i]
            if members[1].startTime and Timer.now >= members[1].startTime and members[1].applyRoom == nil then
                realStartCopy(copyID, members, i)
                cnt = cnt + 1
            end
        end
    end
    
    if timer_cnt > 5 then 
        timer_cnt = 0
        for copyID, signData in pairs(signTeamData) do  --这里再做一次检查，防止断线逻辑报错，没走退出逻辑
            for i = #signData, 1, -1 do
                local members = signData[i]
                local uuids = {}
                for j = 1, #members do
                    uuids[#uuids+1] = members[j].uuid
                end
                
                for j = 1, #uuids do
                    local h = Human.onlineUuid[uuids[j]]
                    if not h or not h.fd then                    
                        remove(uuids[j], copyID)                        
                    end 
                end
            end
        end
    end
end


function removeAll(copyID, match, index)
    local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
    msg.copyID = copyID
    msg.exitType = EXIT_SIGN_TYPE_TEAM_EXIT
    for i = 1, #match do
        local h = Human.onlineUuid[match[i].uuid]
        if h and h.fd then
          Msg.send(msg, h.fd)
        end
    end
    local signData = signTeamData[copyID]
    if signData then
      signData[index] = signData[#signData]
      signData[#signData] = nil
    end
end
-- on LoginOut
function onLogout(human)
    if signHuman2CopyID[human._id] == nil then
        return
    end  
    remove(human._id, signHuman2CopyID[human._id])
end

--队员退出回调
function onDelMemberCB(team, uuid)
    local copyID = signHuman2CopyID[uuid]
    if not copyID then
        return
    end
    local match, index = findSignData(uuid, copyID)
    if not match then
        signHuman2CopyID[uuid] = nil
        return
    end
    local removeUuids = remove(uuid, copyID, match, index)
    if removeUuids then
        local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
        msg.copyID = copyID
        msg.exitType = EXIT_SIGN_TYPE_TEAM_EXIT
        for j = 1, #removeUuids do
            Msg.send(msg, Human.onlineUuid[removeUuids[j]].fd)
        end
    end
end

--队员进入副本
function onBeginCopy(uuid, copyID)
    if signHuman2CopyID[uuid] == nil then
        return
    end  
    local removeUuids = remove(uuid, signHuman2CopyID[uuid])
    if removeUuids then
        local msg = Msg.gc.GC_COPY_TEAM_SIGN_EXIT
        msg.copyID = copyID
        msg.exitType = EXIT_SIGN_TYPE_COPY_OTHER
        for j = 1, #removeUuids do
            Msg.send(msg, Human.onlineUuid[removeUuids[j]].fd)
        end
    end
end

--队长改变
function onChangeLeader(team, uuid)
    onDelMemberCB(team, uuid)
end
